<?php


class Resort_projects extends MY_Controller{
    
    public function __construct() {
        parent::__construct();
        
        $this->load->database();
    }
    
    public function index(){
        $types = array(
            TYPE_LANDED_PROPERTY,
            TYPE_CITY,
            TYPE_ROAD,
            TYPE_LIGHT
        );
        
        foreach($types as $type){
            $sql = "select id,created_at from jg_entry where type='{$type}'";
            $query = $this->db->query($sql);
            $ids = array();
            $times = array();
            foreach($query->result() as $item){
                $ids[] = $item->id;
                $times[] = $item->created_at;
            }
            
            rsort($ids);
            
            $data = array();
            
            foreach($ids as $key=>$id){
                $data[] = array(
                    'id' => $id,
                    'created_at' => $times[$key]
                );
            }
            print_r($data);
            echo '<br/></br><hr/>';
            $this->db->update_batch('jg_entry',$data,'id');
        }
    }
}